package com.piao.manager;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ImageView;

import com.piao.R;
import com.squareup.picasso.Callback;
import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.NetworkPolicy;
import com.squareup.picasso.Picasso;

/**
 * Created by sunfusheng on 16/4/6.
 */
public class ImageLoader {

    private static final String TAG = "ImageLoader";
    private Context mContext;
    public static final String ANDROID_RESOURCE = "android.resource://";
    public static final String FOREWARD_SLASH = "/";

    public ImageLoader(Context context) {
        this.mContext = context;
    }

    // 将资源ID转为Uri
    public Uri resourceIdToUri(int resourceId) {
        return Uri.parse(ANDROID_RESOURCE + mContext.getPackageName() + FOREWARD_SLASH + resourceId);
    }

    // 加载网络图片
    public void loadUrlImage(String url, ImageView imageView) {
        if (TextUtils.isEmpty(url)) {
            Log.e(TAG, "url  isEmpty");
            return;
        }
        Picasso.with(mContext)
                .load(url)
                .placeholder(R.drawable.ic_drawable_default)
                .error(R.drawable.ic_drawable_default)
                .into(imageView);
    }




}
